package com.swotxu.firstribbonclient.customrule;

import com.netflix.loadbalancer.ILoadBalancer;
import com.netflix.loadbalancer.IRule;
import com.netflix.loadbalancer.Server;

import java.util.List;

/**
 * @Date: 2020/7/12 16:36
 * @Author: swotXu
 */
public class MyRule implements IRule {
    ILoadBalancer iLoadBalancer;

    public MyRule() {
    }

    public MyRule(ILoadBalancer iLoadBalancer) {
        this.iLoadBalancer = iLoadBalancer;
    }

    public Server choose(Object key) {
        List<Server> servers = iLoadBalancer.getAllServers();
        return servers.get(0);
    }

    public void setLoadBalancer(ILoadBalancer iLoadBalancer) {
        this.iLoadBalancer = iLoadBalancer;
    }

    public ILoadBalancer getLoadBalancer() {
        return iLoadBalancer;
    }
}
